package com.example.work1;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "main2";

    //获取用户输入

    EditText input = findViewById(R.id.txtout);
    TextView output;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        input = findViewById(R.id.inp_w);
        //获取用户输入数据
        String str = input.getText().toString();

        output = findViewById(R.id.txtout);
        output.setText("Hello AAAAAA");

        System.out.println("this is system.out");
        Log.i("tag1","这里是输入消息");
    }


    public void myClick(View v){
        Log.i(TAG, "myClick: 1111111");
        Log.i(TAG, "myClick: myClick: ");

        //获取用户输入
        EditText inputW = findViewById(R.id.inp_w);
        EditText inputH = findViewById(R.id.inp_h);
        String strW = inputW.getText().toString();
        String strH = inputH.getText().toString();
        if(strW.length()*strH.length()==0){
          output.setText("请输入内容");
            return;
        }
        try {


            //计算过程String--->float/double
            float w = Float.parseFloat(strW);
            float h = Float.parseFloat(strH);
            float bmi = w / (h * h);

            //显示到控件中
            output = findViewById(R.id.txtout);
            output.setText("计算结果为：" + bmi);
            if (bmi < 18) {
                System.out.println("要好好吃饭噢");

            } else if (bmi < 24) {
                System.out.println("你拥有完美身材，注意保持呐");

            } else if (bmi > 28) {
                System.out.println("平时多注意饮食，少吃重油重盐，热量高的食物");

            }
        }catch (NumberFormatException e){
            output.setText("请输入正确的数据");
        }
    }
}